<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { loginServer } from '@/api/user';
import { useUserStore } from '@/stores'
const router = useRouter()
const userStore = useUserStore()
const loginForm = ref({
  username: '',
  password: ''
})
const login = async () => {
  const res = await loginServer(loginForm.value)
  console.log(res.data)
  userStore.setUser(res.data)
  userStore.setToken(res.data.token)
  router.push('/layout')
}
</script>

<template>
  <div class="login">
    <el-card style="max-width: 650px;min-width: 560px">
      <template #header>
        <div class="title">
          <span>图书借阅系统</span>
        </div>
      </template>
      <div class="login-from">
        <el-form label-width="auto" :model="loginForm">
          <el-form-item label="用户名">
            <el-input v-model="loginForm.username"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="loginForm.password" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="login">登录</el-button>
          </el-form-item>
        </el-form>
  
      </div>
    </el-card>
  </div>
</template>

<style scoped>
.login {
  /* 居中 */
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  /* 背景色 */
  background-color: #f5f5f5;
  /* 背景图片 */
  background-image: url('src/assets/image.png');
  background-size: cover;
  /* 背景模糊 */
  backdrop-filter: blur(10px);
  /* 背景模糊 */
  background-blend-mode: multiply;
  /* 背景模糊 */
  background-color: rgba(255, 255, 255, 0.5);
}

.el-card,
.login-form {
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
